package ele_handler

import "fmt"

func init() {
	registerInitFunc(
		func() YuqueElementHandler {
			a := &articleHandlerStruct{}
			a.elements = []string{"article"}
			return a
		})
}

type articleHandlerStruct struct {
	BaseHandler
	nodeId string
}

func (a *articleHandlerStruct) preHandle() (err error) {

	nodeId := findAttribute(a.node, "id")
	if len(nodeId) <= 0 {
		return fmt.Errorf("article id is empty")
	}

	a.nodeId = nodeId

	a.ctxMap["wrapArticle_"+nodeId] = true

	a.WriteTextContext("\n")

	return
}

func (a *articleHandlerStruct) postHandle() (err error) {

	if len(a.nodeId) <= 0 {
		return
	}

	delete(a.ctxMap, "wrapArticle_"+a.nodeId)

	a.WriteTextContext("\n")

	return
}
